package cn.iocoder.an.module.mold.service.repairstatics;

import cn.hutool.core.collection.CollUtil;
import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.an.module.mold.controller.admin.repairstatics.vo.*;
import cn.iocoder.an.module.mold.dal.dataobject.repairstatics.RepairStaticsDO;
import cn.iocoder.an.framework.common.pojo.PageResult;
import cn.iocoder.an.framework.common.pojo.PageParam;
import cn.iocoder.an.framework.common.util.object.BeanUtils;

import cn.iocoder.an.module.mold.dal.mysql.repairstatics.RepairStaticsMapper;

import static cn.iocoder.an.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.an.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.an.framework.common.util.collection.CollectionUtils.diffList;
import static cn.iocoder.an.module.mold.enums.ErrorCodeConstants.*;

/**
 * 维修统计 Service 实现类
 *
 * @author 超级管理员
 */
@Service
@Validated
public class RepairStaticsServiceImpl implements RepairStaticsService {

    @Resource
    private RepairStaticsMapper repairStaticsMapper;

    @Override
    public Long createRepairStatics(RepairStaticsSaveReqVO createReqVO) {
        // 插入
        RepairStaticsDO repairStatics = BeanUtils.toBean(createReqVO, RepairStaticsDO.class);
        repairStaticsMapper.insert(repairStatics);

        // 返回
        return repairStatics.getId();
    }

    @Override
    public void updateRepairStatics(RepairStaticsSaveReqVO updateReqVO) {
        // 校验存在
        validateRepairStaticsExists(updateReqVO.getId());
        // 更新
        RepairStaticsDO updateObj = BeanUtils.toBean(updateReqVO, RepairStaticsDO.class);
        repairStaticsMapper.updateById(updateObj);
    }

    @Override
    public void deleteRepairStatics(Long id) {
        // 校验存在
        validateRepairStaticsExists(id);
        // 删除
        repairStaticsMapper.deleteById(id);
    }

    @Override
        public void deleteRepairStaticsListByIds(List<Long> ids) {
        // 删除
        repairStaticsMapper.deleteByIds(ids);
        }


    private void validateRepairStaticsExists(Long id) {
        if (repairStaticsMapper.selectById(id) == null) {
            throw exception(REPAIR_STATICS_NOT_EXISTS);
        }
    }

    @Override
    public RepairStaticsDO getRepairStatics(Long id) {
        return repairStaticsMapper.selectById(id);
    }

    @Override
    public PageResult<RepairStaticsDO> getRepairStaticsPage(RepairStaticsPageReqVO pageReqVO) {
        return repairStaticsMapper.selectPage(pageReqVO);
    }

}